package com.yange.accountbook.ui

import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import com.yange.accountbook.databinding.AddItemLayoutBinding
import com.yange.accountbook.entity.AccountEntity
import com.yange.accountbook.ui.adapter.BaseFragmentPagerAdapter


/**
 * 添加明细 activity
 */
class AddItemActivity:BaseActivity<AddItemLayoutBinding>() {

    private var titleList = mutableListOf("支出", "收入","分账","转账" +
            "")
    var pagerAdapter: BaseFragmentPagerAdapter? = null
    override fun getViewBinding() = AddItemLayoutBinding.inflate(layoutInflater)

    override fun init() {
        val fragmentList = mutableListOf<Fragment>()
        var accountId = intent.getIntExtra("accountId", 0)
        var bookId = intent.getIntExtra("bookId",0)

        fragmentList.add(AddItemInFragment.newInstance(AddItemInFragment().TYPE_OUT, accountId, bookId))
        fragmentList.add(AddItemInFragment.newInstance(AddItemInFragment().TYPE_IN, accountId, bookId))
        fragmentList.add(AddItemInFragment.newInstance(AddItemInFragment().TYPE_SPLIT, accountId, bookId))
        fragmentList.add(AddItemInFragment.newInstance(AddItemInFragment().TYPE_TRANSFER, accountId, bookId))
        pagerAdapter = BaseFragmentPagerAdapter(fragmentList, titleList, supportFragmentManager)
        binding.viewpager.adapter = pagerAdapter
        binding.tabLayout.setupWithViewPager(binding.viewpager)
    }

    companion object{
        fun start(context: Context ){
            var intent = Intent(context,AddItemActivity().javaClass)
            context.startActivity(intent)
        }
        fun startByAccount(context: Context, account: AccountEntity ){
            var intent = Intent(context,AddItemActivity().javaClass)
            intent.putExtra("accountId", account.id)
            intent.putExtra("bookId", account.bookId)
            context.startActivity(intent)
        }
    }


}
